<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags/general" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<c:set var="basePath" value="${pageContext.servletContext.contextPath}"/>
<t:template>
<div style ="background-color:white;">
	<c:if test="${fn:length(accounts) > 0}">
	<table>
		<tr class="m">
			<td rowspan="2"><b>Konts</b></td>
			<td colspan="4" align="center"><b>Bilance</b></td>
			<td rowspan="2"><b>Bilance (LVL)</b></td>
			<td rowspan="2"><b>Pēdējās izmaiņas</b></td>
		</tr>
		<tr class="m" >
			<td><b>Valūta</b></td>
			<td><b>Faktiskais</b></td>
			<td><b>Rezervēts</b></td>
			<td><b>Pieejams</b></td>
		</tr>

		<c:set var="balance" value="0"/>
		<c:forEach items="${accounts}" var="account">
		<tr class="m row">
			<c:set var="balance" value="${balance + account[2]}"/>
			<td>${account[1]}</td>
			<td>${account[4]}</td>
			<td><fmt:formatNumber value="${account[2]}" pattern="#.##"/></td>
			<td><fmt:formatNumber value="${account[2]}" pattern="#.##"/></td>
			<td><fmt:formatNumber value="${account[2]}" pattern="#.##"/></td>
			<td><fmt:formatNumber value="${account[2]}" pattern="#.##"/></td>
			<td>${account[3]}</td>
		</tr>
		</c:forEach>
	
		<tr class="m">
			<td colspan="5" align="right"><b>Kopā:</b> </td>
			<td><fmt:formatNumber value="${balance}" pattern="#.##"/></td>
			<td></td>
		</tr>
	</table>
	</c:if>
	<div id="exc">	
	<c:if test="${fn:length(accounts) < 1}">
		<table>
			<tr>
				<td colspan="7">You have no accounts. Please add account <a href="${basePath}/bank/ibank/accounts/add" >here</a></td>
			</tr>
		</table>
	</c:if>
	</div>	
</div>
</t:template>

